package cn.ym.mall.vo;

import java.io.Serializable;

/**
 * 消息公共类
 */
public class CommonResult<T> implements Serializable {
    private long code;// 返回状态码
    private String message;// 返回消息
    private T data;// 返回数据

    public CommonResult() {
    }

    public CommonResult(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 成功的默认信息
     * @return
     */
    public static CommonResult success(){
        return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), null);
    }

    /**
     * 成功的信息提示
     * @return
     */
    public static CommonResult success(String message){
        return new CommonResult(ResultCode.SUCCESS.getCode(),message,null);
    }

    /**
     * 成功的数据信息
     * @return
     */
    public static <T>CommonResult success(T data){
        return new CommonResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(), data);
    }

    /**
     * 成功的数据信息
     * @return
     */
    public static <T>CommonResult success(String message,T data){
        return new CommonResult(ResultCode.SUCCESS.getCode(),message, data);
    }

    /**
     * 失败的默认信息
     * @return
     */
    public static CommonResult failed(){
        return new CommonResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(), null);
    }

    /**
     * 失败的code
     * @return
     */
    public static CommonResult failed(long code){
        return new CommonResult(code, ResultCode.FAILED.getMessage(), null);
    }

    /**
     * 失败的code
     * @return
     */
    public static CommonResult failed(String message){
        return new CommonResult(ResultCode.FAILED.getCode(), message, null);
    }

    /**
     * 失败的code
     * @return
     */
    public static CommonResult failedMethod(){
        return new CommonResult(ResultCode.FAILED_URL_METHOD.getCode(), ResultCode.FAILED_URL_METHOD.getMessage(), null);
    }
}
